package cn.dmrliu.edu.publish.controller;

import cn.dmrliu.edu.publish.bean.ToolVideoChapter;
import cn.dmrliu.edu.publish.service.ToolVideoChapterService;
import cn.dmrliu.edu.publish.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/edu/realtime/video")
public class VideoController {

    @Autowired
    ToolVideoChapterService toolVideoChapterService;

    @RequestMapping("/chapter")
    public String getChapterStats(@RequestParam(value = "date", defaultValue = "1") Integer date) {
        if (date == 1) {
            date = DateUtil.now();
        }

        List<ToolVideoChapter> list = toolVideoChapterService.getToolVideoChapter(date);

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"total\": 13,\n" +
                "    \"columns\": [\n" +
                "      {\n" +
                "        \"name\": \"章节名称\",\n" +
                "        \"id\": \"chapterName\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"视频播放次数\",\n" +
                "        \"id\": \"playCt\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"累积播放时长\",\n" +
                "        \"id\": \"durSum\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"观看人数\",\n" +
                "        \"id\": \"playNum\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"人均观看时长\",\n" +
                "        \"id\": \"avgDur\",\n" +
                "        \"accuracy\": 2\n" +
                "      }\n" +
                "    ],\n" +
                "    \"rows\": [" + StringUtils.join(list, ",") + "]\n " +
                "  }\n" +
                "}";

    }

}
